package com.fbt.energy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fbt.energy.dao.AmmeterDao;
import com.fbt.energy.entity.Ammeter;
import com.fbt.energy.entity.ProductionLine;
import com.fbt.energy.dao.ProductionLineDao;
import com.fbt.energy.service.ProductionLineService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 产线表(ProductionLine)表服务实现类
 *
 * @author makejava
 * @since 2021-12-12 19:06:54
 */
@Service("productionLineService")
public class ProductionLineServiceImpl  extends ServiceImpl<ProductionLineDao, ProductionLine> implements ProductionLineService {
    @Resource
    private ProductionLineDao productionLineDao;

    /**
     * 通过ID查询单条数据
     *
     * @param productionLineId 主键
     * @return 实例对象
     */
    @Override
    public ProductionLine queryById(Integer productionLineId) {
        return this.productionLineDao.queryById(productionLineId);
    }

    /**
     * 分页查询
     *
     * @param productionLine 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ProductionLine> queryByPage(ProductionLine productionLine, PageRequest pageRequest) {
        long total = this.productionLineDao.count(productionLine);
        return new PageImpl<>(this.productionLineDao.queryAllByLimit(productionLine, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param productionLine 实例对象
     * @return 实例对象
     */
    @Override
    public ProductionLine insert(ProductionLine productionLine) {
        this.productionLineDao.insert(productionLine);
        return productionLine;
    }

    /**
     * 修改数据
     *
     * @param productionLine 实例对象
     * @return 实例对象
     */
    @Override
    public ProductionLine update(ProductionLine productionLine) {
        this.productionLineDao.update(productionLine);
        return this.queryById(productionLine.getProductionLineId());
    }

    /**
     * 通过主键删除数据
     *
     * @param productionLineId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer productionLineId) {
        return this.productionLineDao.deleteById(productionLineId) > 0;
    }
}
